import collections
import copy


class Solution:
    def hw(self, int_input: int):
        res = 0
        for i in range(32):
            res += ((int_input >> i) & 1)
        return res


    def countPairs0(self, deliciousness) -> int:
        res = 0
        possible = []
        for i in range(24):
            possible.append(1 << i)
        for i in range(len(deliciousness)):
            value_a = deliciousness[0]
            deliciousness.pop(0)
            for one_sum in possible:
                res += deliciousness.count(one_sum - value_a)
        return res


    def countPairs(self, deliciousness) -> int:
        res = 0
        possible = [1]
        while possible[-1] < max(deliciousness) * 2:
            possible.append(possible[-1] << 1)
        statistics = collections.Counter(deliciousness)
        values = list(statistics.keys())
        for element in values:
            for one_sum in possible:
                if one_sum - element == element:
                    res += (statistics[element] * (statistics[element] - 1) // 2)
                else:
                    res += statistics[element] * statistics[one_sum - element]
            print(res)
            statistics.pop(element)
        return res

deli = [32] * 10000
a = Solution()
print(a.countPairs(deli))